
data{
int<lower=0>N; //observations
int<lower=0>K; // covariates
int<lower=2>E;
int<lower=2, upper=E> ep[N];
matrix[N,K] x; // matrix of covariates
real y[N];
}

transformed data{
real zeros[K];
for(k in 1:K){
zeros[k]<-0.0; // this creates 0's to put in sigma's for betas
}
}

parameters {
vector[K] beta; //coefficients
vector[E] ranef_e; // 
vector<lower=0, upper=100>[K] sigma_beta; //sigmas for betas
real<lower=0, upper=100> sigma_e; //sigma for country
real<lower=0, upper=100> sigma_y; //sigma for 
}


transformed parameters {
vector[N] eta;
vector[N] y_hat;
eta<-x*beta;

for(n in 1:N){
y_hat[n]<-eta[n] + ranef_e[ep[n]] ;
}

}

model {
//priors
sigma_y ~ uniform(0,100);
beta ~ normal(zeros, sigma_beta);
sigma_e ~ cauchy(0,2.5);


//likelihood
y ~ normal(y_hat, sigma_y);
ranef_e ~ normal(0, sigma_e);
}

generated quantities{
real diff_expv_m3n;
real diff_expv_m3p;
real controls;

controls<-beta[1]  + beta[4]*6.770396  + beta[5]*1 + beta[6]*3.764045  + beta[7]*.2319347 + beta[8]*.028781 + beta[9] + beta[23]; /// epgroup2, natparty 12;

diff_expv_m3p<-(controls + beta[2]*.1089152 + beta[3]*.04409997)-(controls + beta[2]*.1089152 + beta[3]*.00173229);


diff_expv_m3n<-(controls + beta[2]*.15743667 + beta[3]*.0229161)-(controls + beta[2]*.06039371 + beta[3]*.0229161);
}




